﻿using DAL.Repositories;
using Data.DBModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebIndex1
{
    public class Helper
    {
        public static User GetUser(UserRepository userRepository)
        {
            User user = null;
            var request = HttpContext.Current.Request;
            if(request.IsAuthenticated)
            {
                string username = HttpContext.Current.User.Identity.Name;
                user = userRepository.First(item => item.Username == username);
            }
            return user;
        }

        public static string GetCookie(string cookieName)
        {
            return HttpContext.Current.Request.Cookies[cookieName] == null ? string.Empty : HttpContext.Current.Request.Cookies[cookieName].Value;
        }
    }
}